package com.fc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fc.checkGroup.Delete;
import com.fc.checkGroup.Insert;
import com.fc.checkGroup.Update;
import com.fc.entity.Employee;
import com.fc.entity.UserAddressRelation;
import com.fc.entity.input.AddressInput;
import com.fc.entity.input.DeleteBatchInput;
import com.fc.entity.input.EmployeeInput;
import com.fc.entity.input.EmployeeQueryInput;
import com.fc.entity.output.AddressOutput;
import com.fc.entity.output.EmployeeOutput;
import com.fc.entity.query.PageQuery;
import com.fc.entity.query.PageResult;
import com.fc.service.AddressService;
import com.fc.service.EmployeeService;
import com.fc.utils.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 地址表 前端控制器
 * </p>
 *
 * @author
 * @since 2024-11-04
 */
@RestController
@RequestMapping("/address")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "地址管理")
@Validated
public class AddressController {

    private final AddressService addressService;

    /**
     * 新增
     */
    @Operation(summary = "新增")
    @PostMapping("/add")
    public ResultVO<String> add(@Validated(Insert.class) @RequestBody AddressInput input) {
        log.info("————地址新增");
        return addressService.add(input) ? ResultVO.success("新增成功") : ResultVO.error("新增失败");
    }

    /**
     * 分页模糊查询
     */
    @Operation(summary = "分页模糊查询")
    @GetMapping("/page")
    public ResultVO<PageResult<AddressOutput>> getPage(PageQuery query) {
        log.info("————地址分页查询");
        return ResultVO.success(addressService.getPage(query));
    }

    /**
     * 修改
     */
    @Operation(summary = "修改")
    @PostMapping("/renew")
    public ResultVO<String> renew(@Validated(Update.class) @RequestBody AddressInput input) {
        log.info("————地址修改");
        return addressService.renew(input) ? ResultVO.success("修改成功") : ResultVO.error("修改失败");
    }

    /**
     * 删除
     */
    @Operation(summary = "删除")
    @PostMapping("/del")
    public ResultVO<String> del(@Validated(Delete.class) @RequestBody DeleteBatchInput input) {
        log.info("————地址删除");
        return addressService.del(input) ? ResultVO.success("删除成功") : ResultVO.error("删除失败");
    }

    /**
     * 查询详情
     */
    @Operation(summary = "查询详情")
    @GetMapping("/detail")
    public ResultVO<AddressOutput> detail(@NotNull(message = "id不能为空") Long id) {
        log.info("————地址详情");
        return addressService.detail(id);
    }
}
